package com.zjzywl.smoke.controller;



import javax.websocket.server.PathParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import com.zjzywl.smoke.config.AppConfig;
import com.zjzywl.smoke.util.WebResult;

@RestController
@RequestMapping(value = "/deviceStatus")
public class DeviceStatusController extends BaseController {
	@Autowired
	private AppConfig appConfig;

	// 根据设备编码获取设备
	@RequestMapping(value = "/get/code")
	@ResponseBody
	public WebResult getByCode(@PathParam("devicecode") String deviceCode) {
		ResponseEntity<Object> deviceTypes = appConfig.restTemplate().exchange(
				appConfig.getGetDataIp() + "/deviceStatus/get/code/" + deviceCode, HttpMethod.GET, null, Object.class);
		return WebResult.OK(deviceTypes);
	}

	// 查询设备：根据设备状态查询
	@RequestMapping(value = "/data/list/bydevicetype")
	public WebResult getDSByDeviceTypeAndUser(@PathParam("deviceTypeId") String deviceTypeId,
			@PathParam("status") String status, @PathParam("devCode") String devCode,@PathParam("address") String address) {
		String userId = this.getUserId();
		ResponseEntity<Object> deviceTypes = appConfig.restTemplate().exchange(appConfig.getGetDataIp()
				+ "/deviceStatus/data/list/bydevicetype/" + deviceTypeId + "/" + userId + "/" + status + "/" + devCode+"/"+address,
				HttpMethod.GET, null, Object.class);
		return WebResult.OK(deviceTypes);
	}
	
	/*
     * 根据设备类型及用户信息获取设备状态数据new
     */
    @RequestMapping(value = "/data/list/bydevicetypeNew")
    public WebResult getDSByDeviceTypeAndUserNew(@RequestParam("deviceTypeId") Integer deviceTypeId) {
        String userId = this.getUserId();
        ResponseEntity<Object> deviceTypes = appConfig.restTemplate().exchange(appConfig.getGetDataIp()
                + "/deviceStatus/data/list/bydevicetypeNew?deviceTypeId=" + deviceTypeId + "&userId=" + userId ,
                HttpMethod.GET, null, Object.class);
        return WebResult.OK(deviceTypes);
    }

//	// 查询设备数量：根据设备状态查询
//	@RequestMapping(value = "/data/count/bydevicetype")
//	public WebResult getDCyDeviceTypeAndUser(@PathParam("deviceTypeId") String deviceTypeId,
//			@PathParam("status") String status, @PathParam("devCode") String devCode) {
//		String userId = this.getUserId();
//		ResponseEntity<Object> deviceTypes = appConfig.restTemplate().exchange(appConfig.getGetDataIp()
//				+ "/deviceStatus/data/count/bydevicetype/" + deviceTypeId + "/" + userId + "/" + status + "/" + devCode,
//				HttpMethod.GET, null, Object.class);
//		
//		return WebResult.OK(deviceTypes);
//	}

}
